package leetcodecompetition.D337;

import org.junit.jupiter.api.Test;
import tool.s;

import java.util.*;

public class T6352 {
    public int beautifulSubsets(int[] nums, int k) {
        Arrays.sort(nums);
        int len=nums.length;
        if (len==1)return 1;
        Set<Integer> hash=new HashSet<>();
        return beautifulSubsetsHelp(nums,k,hash,len);
    }
    public int beautifulSubsetsHelp(int[] nums,int k,Set<Integer> h,int n){
        Set<Integer> hash=new HashSet<>();
        int sum=0;
        for (int i = 0; i <n ; i++) {
            if (h.contains(nums[i])){
                continue;
            }
            if (hash.contains(nums[i]-k)){
                h.add(nums[i]-k);
                sum+=beautifulSubsetsHelp(nums,k,h,i)+1;
                h.remove(nums[i]-k);
            }else {
                sum+=sum+1;
            }
            hash.add(nums[i]);
        }
        return sum;
    }
    @Test
    public void test() {
        int []ints={2,4,6};
        System.out.println(beautifulSubsets(ints,2));
    }
}
